<?php

class Core_Backend_Component_Permission_View_Role_Create extends Core_Backend_Share_View_Form {

    protected function initialize() {
        parent::initialize();
        $this->setTemplatePath('edit');
    }
    
    protected function buildToolbar($toolbar) {
        $group = $toolbar->createGroup('back');
        $group->addLink($this->getHistoryUrl('permission/role/index'), $this->__('share.button.back'));
        $group = $toolbar->createGroup('save');
        $group->addButton($this->__('share.button.save'))
                ->bindEvent('click', "Kdf.Ui.getForm('" . $this->getForm()->getId() . "').submit('" . $this->getUrl(NULL, 'save') . "')");
        parent::buildToolBar($toolbar);
    }

    protected function buildForm($form) {
        $entity = $this->getModel(NULL);
        $form->setAction($this->getUrl())
                ->setId('role_form')
                ->addHiddenField('id', 'role[id]')
                ->addHiddenField('area_id', 'role[area_id]', $this->getSession()->get('managed_area_id'));
        $form->addTextboxField($this->__('share.label.code'), 'code', 'role[code]', TRUE)
                ->addMultiRule('required', 'character');
        $form->addTextboxField($this->__('share.label.name'), 'name', "role[name]", TRUE)
                ->addRequiredRule();
        $form->addComboTreeField($this->__('permission.label.parentRole'), 'parent_id', 'role[parent_id]')
        		->setDefaultOption('0', '--')
                ->bindData($this->getRoles()->toArray(), 0, array('valueKey' => 'id', 'textKey' => 'name', 'parentKey' => 'parent_id', 'childKey' => 'id'));                
        $form->addCheckListField($this->__('permission.label.select_action'), 'action_ids', 'role[action_ids][]')
        		->setGroupable(TRUE)
                ->bindData($this->getActions()->toArray(), 'name', 'id', 'group');                
//        $form->addSelectField($this->__('permission.label.select_action'), 'action_ids', 'role[action_ids][]')
//        		->setSize(20)
//        		->setMultiple(TRUE)
//                ->bindData($this->getActions()->toArray(), 'name', 'id');
        if (!is_null($entity)) {
            $form->bindData($entity->getAllData());
        }
        parent::buildForm($form);
    }

}